<?php

namespace App\Admin\Actions\Grid\Ding;

use App\Exceptions\AdminInvalidRequestException;
use App\Models\Ding;
use App\Services\DingTalkPush;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Support\Facades\Artisan;

class Department extends RowAction
{
    /**
     * @return string
     */
    protected $title = '更新部门';

    /**
     * Handle the action request.
     *
     * @return Response
     * @throws AdminInvalidRequestException
     */
    public function handle(): Response
    {
        $app = new DingTalkPush(Ding::query()->where('id', $this->getKey())->value('corp_id'));
        $app->updateDepartment();
        return $this->response()->success('更新成功')->refresh();
    }


    public function html(): string
    {
        $this->defaultHtmlAttribute('href', 'javascript:void(0)');

        return <<<HTML
<a {$this->formatHtmlAttributes()}><i class="feather icon-refresh-cw"> {$this->title()}</i></a>
HTML;
    }
}
